﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    static class Input
    {

        private static KeyboardState ks;
        private static KeyboardState old_ks;

        public static bool anyKeyDown
        {
            get
            {
                if (Keyboard.GetState().GetPressedKeys().Length == 0) return false;
                switch (Keyboard.GetState().GetPressedKeys().First<Keys>())
                {
                    case Keys.A:
                    case Keys.Add:
                    case Keys.Apps:
                    case Keys.Attn:
                    case Keys.B:
                    case Keys.Back:
                    case Keys.BrowserBack:
                    case Keys.BrowserFavorites:
                    case Keys.BrowserForward:
                    case Keys.BrowserHome:
                    case Keys.BrowserRefresh:
                    case Keys.BrowserSearch:
                    case Keys.BrowserStop:
                    case Keys.C:
                    case Keys.CapsLock:
                    case Keys.ChatPadGreen:
                    case Keys.ChatPadOrange:
                    case Keys.Crsel:
                    case Keys.D:
                    case Keys.D0:
                    case Keys.D1:
                    case Keys.D2:
                    case Keys.D3:
                    case Keys.D4:
                    case Keys.D5:
                    case Keys.D6:
                    case Keys.D7:
                    case Keys.D8:
                    case Keys.D9:
                    case Keys.Decimal:
                    case Keys.Delete:
                    case Keys.Divide:
                    case Keys.Down:
                    case Keys.E:
                    case Keys.End:
                    case Keys.Enter:
                    case Keys.EraseEof:
                    case Keys.Escape:
                    case Keys.Execute:
                    case Keys.Exsel:
                    case Keys.F:
                    case Keys.F1:
                    case Keys.F10:
                    case Keys.F11:
                    case Keys.F12:
                    case Keys.F13:
                    case Keys.F14:
                    case Keys.F15:
                    case Keys.F16:
                    case Keys.F17:
                    case Keys.F18:
                    case Keys.F19:
                    case Keys.F2:
                    case Keys.F20:
                    case Keys.F21:
                    case Keys.F22:
                    case Keys.F23:
                    case Keys.F24:
                    case Keys.F3:
                    case Keys.F4:
                    case Keys.F5:
                    case Keys.F6:
                    case Keys.F7:
                    case Keys.F8:
                    case Keys.F9:
                    case Keys.G:
                    case Keys.H:
                    case Keys.Help:
                    case Keys.Home:
                    case Keys.I:
                    case Keys.ImeConvert:
                    case Keys.ImeNoConvert:
                    case Keys.Insert:
                    case Keys.J:
                    case Keys.K:
                    case Keys.Kana:
                    case Keys.Kanji:
                    case Keys.L:
                    case Keys.LaunchApplication1:
                    case Keys.LaunchApplication2:
                    case Keys.LaunchMail:
                    case Keys.Left:
                    case Keys.LeftAlt:
                    case Keys.LeftControl:
                    case Keys.LeftShift:
                    case Keys.LeftWindows:
                    case Keys.M:
                    case Keys.MediaNextTrack:
                    case Keys.MediaPlayPause:
                    case Keys.MediaPreviousTrack:
                    case Keys.MediaStop:
                    case Keys.Multiply:
                    case Keys.N:
                    case Keys.None:
                    case Keys.NumLock:
                    case Keys.NumPad0:
                    case Keys.NumPad1:
                    case Keys.NumPad2:
                    case Keys.NumPad3:
                    case Keys.NumPad4:
                    case Keys.NumPad5:
                    case Keys.NumPad6:
                    case Keys.NumPad7:
                    case Keys.NumPad8:
                    case Keys.NumPad9:
                    case Keys.O:
                    case Keys.Oem8:
                    case Keys.OemAuto:
                    case Keys.OemBackslash:
                    case Keys.OemClear:
                    case Keys.OemCloseBrackets:
                    case Keys.OemComma:
                    case Keys.OemCopy:
                    case Keys.OemEnlW:
                    case Keys.OemMinus:
                    case Keys.OemOpenBrackets:
                    case Keys.OemPeriod:
                    case Keys.OemPipe:
                    case Keys.OemPlus:
                    case Keys.OemQuestion:
                    case Keys.OemQuotes:
                    case Keys.OemSemicolon:
                    case Keys.OemTilde:
                    case Keys.P:
                    case Keys.Pa1:
                    case Keys.PageDown:
                    case Keys.PageUp:
                    case Keys.Pause:
                    case Keys.Play:
                    case Keys.Print:
                    case Keys.PrintScreen:
                    case Keys.ProcessKey:
                    case Keys.Q:
                    case Keys.R:
                    case Keys.Right:
                    case Keys.RightAlt:
                    case Keys.RightControl:
                    case Keys.RightShift:
                    case Keys.RightWindows:
                    case Keys.S:
                    case Keys.Scroll:
                    case Keys.Select:
                    case Keys.SelectMedia:
                    case Keys.Separator:
                    case Keys.Sleep:
                    case Keys.Space:
                    case Keys.Subtract:
                    case Keys.T:
                    case Keys.Tab:
                    case Keys.U:
                    case Keys.Up:
                    case Keys.V:
                    case Keys.VolumeDown:
                    case Keys.VolumeMute:
                    case Keys.VolumeUp:
                    case Keys.W:
                    case Keys.X:
                    case Keys.Y:
                    case Keys.Z:
                    case Keys.Zoom:
                        return true;
                        break;
                    default:
                        return false;
                }


            }
        }

        public static bool GetKeyDown(Keys k)
        {
            if(ks != old_ks && ks.IsKeyDown(k)) return true;
            return false;
        }
        public static bool GetKey(Keys k)
        {
            if (ks.IsKeyDown(k)) return true;
            return false;
        }
        public static bool GetKeyUp(Keys k)
        {
            if(ks != old_ks && ks.IsKeyUp(k)) return true;
            return false;
        }
        public static void Update(KeyboardState s)
        {
            old_ks = ks;
            ks = s;
        }


    }
}
